package com.xjrsoft.module.customerTwo.EMP.price_setting.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xjrsoft.common.page.PageOutput;
import com.xjrsoft.common.page.ConventPage;
import java.util.List;
import com.xjrsoft.common.result.Response;
import com.xjrsoft.core.tool.utils.BeanUtil;
import com.xjrsoft.module.customerTwo.EMP.price_setting.dto.TPriceSettingDto;
import com.xjrsoft.module.customerTwo.EMP.price_setting.dto.SaveTPriceSettingFormDataDto;
import com.xjrsoft.module.customerTwo.EMP.price_setting.vo.TPriceSettingVo;
import com.xjrsoft.module.customerTwo.EMP.price_setting.vo.TPriceSettingListVo;
import com.xjrsoft.module.customerTwo.EMP.price_setting.dto.TPriceSettingListDto;
import com.xjrsoft.core.secure.utils.SecureUtil;
import com.xjrsoft.core.tool.utils.FlowableUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;

import org.springframework.web.bind.annotation.*;
import com.xjrsoft.module.customerTwo.EMP.price_setting.entity.TPriceSetting;
import com.xjrsoft.module.customerTwo.EMP.price_setting.vo.TPriceSettingVo;
import com.xjrsoft.module.customerTwo.EMP.price_setting.service.ITPriceSettingService;

/**
 *  控制器
 *
 * @author dongxinhang
 * @since 2023-07-20
 */
@RestController
@AllArgsConstructor
@RequestMapping("/price_setting")
@Api(value = "价格设置", tags = "价格设置接口")
public class TPriceSettingController {


	private final ITPriceSettingService tPriceSettingService;


	/**
	 * 详情 
	 */
	@GetMapping("/{id}")
	@ApiOperation(value = "详情", notes = "传入tPriceSetting")
	@SaCheckPermission(value = {"price_setting:view", "price_setting:modify"}, mode = SaMode.OR)
	public Response<TPriceSettingVo> getFormData(@PathVariable String id) {
		// 主表数据
		TPriceSetting tPriceSetting = tPriceSettingService.getById(id);
		TPriceSettingVo tPriceSettingVo = BeanUtil.copy(tPriceSetting, TPriceSettingVo.class);
		return Response.ok(tPriceSettingVo);
	}

	/**
	 * 自定义分页 
	 */
	@GetMapping
	@ApiOperation(value = "分页", notes = "传入tPriceSetting")
		public Response<PageOutput<TPriceSettingListVo>> getPageList(TPriceSettingListDto listDto) {
		IPage<TPriceSetting> page = tPriceSettingService.getPageList(listDto);
		List<TPriceSettingListVo> records = BeanUtil.copyList(page.getRecords(), TPriceSettingListVo.class);
			// 工作流数据处理
		FlowableUtil.systemFormList(records, SecureUtil.getModuleId());
		return Response.ok(ConventPage.getPageOutput(page.getTotal(), records));
	}

	/**
	 * 新增 
	 */
	@PostMapping
	@ApiOperation(value = "新增", notes = "传入tPriceSetting")
	@SaCheckPermission("price_setting:add")
	public Response save(@RequestBody SaveTPriceSettingFormDataDto formDto) {
		TPriceSettingDto tPriceSettingDto = formDto.getTPriceSettingDto();
		TPriceSetting tPriceSetting = BeanUtil.copy(tPriceSettingDto, TPriceSetting.class);
		String dataId = tPriceSettingService.addTPriceSetting(tPriceSetting);
		return dataId == null ? Response.notOk() : Response.ok(dataId);
	}

	/**
	 * 修改 
	 */
	@PutMapping("/{id}")
	@ApiOperation(value = "修改", notes = "传入tPriceSetting")
	@SaCheckPermission("price_setting:modify")
	public Response update(@PathVariable String id, @RequestBody SaveTPriceSettingFormDataDto formDto) {
		TPriceSettingDto tPriceSettingDto = formDto.getTPriceSettingDto();
		TPriceSetting tPriceSetting = BeanUtil.copy(tPriceSettingDto, TPriceSetting.class);
		return Response.status(tPriceSettingService.updateTPriceSetting(id, tPriceSetting));
	}



	/**
	 * 删除 
	 */
	@DeleteMapping("/{ids}")
	@ApiOperation(value = "删除", notes = "传入ids")
	@SaCheckPermission(value = {"price_setting:batchDelete", "price_setting:delete"}, mode = SaMode.OR)
	public Response remove(@ApiParam(value = "主键集合", required = true) @PathVariable String ids) {
		return Response.status(tPriceSettingService.delete(ids));
	}


}
